|
|
|
|
|
|
|
Working with the Selected Item |
|
|
|
|
|
|
|
|
Each item displayed in the ImageCombo is a member of the ComboItems collection. To determine whether users have selected items, check the SelectedItem property for a reference to the items, as in the following lines of code: |
|
|
|
|
|
|
|
|
If ImageCombo1.SelectedItem Is Nothing Then
' No Item is Selected!
Else
MsgBox "You selected: " & ImageCombo1.SelectedItem.Text
End If |
|
|
|
|
|
|
|
|
|
You can also select an item from code by setting the item's Selected property to True, as in the following example: |
|
|
|
|
|
|
|
|
ImageCombo1.ComboItems(1).Selected = True  |
|
|
|
|
|
|
|
|
|
|
Why do you need to check the SelectedItem property to see whether it is Nothing? As you may recall from using the standard combo box control, users can not only select items from the item list, but they also can enter text in the combo box's input area. The ImageCombo control also exhibits this behavior. If the information in the input area does not represent an item in the list, attempting to access properties of the SelectedItem object causes an error. |
|
|
|
|
|
|
|
|
|
You can force the users to select one of your items from the list by setting the Locked property of the ImageCombo to True, which disables free-form text input.  |
|
|
|
|
|
|
|
|
|
|
As with the standard combo box, the text for the selected or entered item is available via the Text property. |
|
|
|
|
|
|
|
|
Organizing Combo Box Items |
|
|
|
|
|
|
|
|
Another feature of the ImageCombo control is that you can specify a level of indentation for each item in the ComboItems collection. By indenting certain items, you can give your list a sense of organization. |
|
|
|
|
|
|
|
|
To set an item's indentation, you assign the Indentation property an integer value. The Indentation property can also be specified as the final optional parameter in the Add method, as in the following example: |
|
|
|
|
|
|
|
|
cmbMain.ComboItems.Add , "mykey", "mytext", 1, 2, 1 |
|
|
|
|
|
|
|
|
Each indentation level represents 10 pixels. A sample ImageCombo that makes use of the Indentation property is shown in Figure 12.18. |
|
|
|
|
|
|
|
|
Figure 12.18
You can use the Indentation property to organize an ImageCombo list. |
|
|
|
|
|